import Ember from 'ember';
import BaseBusiness from '../base-business';

export default BaseBusiness.extend({
  queryParams: {
      id: {
          refreshModel: true
      },
      editMode: {
          refreshModel: true
      },
  },
  detailEdit:true,
  header_title:'护理组信息',
  model(){
    return{};
  },

  setupController(controller, model){
    this._super(controller, model);
    var editMode=this.getCurrentController().get('editMode');
    var id=this.getCurrentController().get('id');
    if(id!==0&&editMode=='edit'){
      controller.set('detailEdit',false);
      this.store.findRecord('nursegroup',id).then(function(nurseGroupInfo){
          var mainController=App.lookup('route:business.mainpage.nursing-worker-group-management');
          mainController.getStaffByNurseGroup(nurseGroupInfo);
          controller.set('nurseGroupInfo',nurseGroupInfo);
      });

    }else{
      controller.set('id',0);
      id=0;
      controller.set('nurseGroupInfo',this.get("store").createRecord('nursegroup', {}));
      controller.set('detailEdit',true);
    }

    var staffArr=[];
    this.store.query('user',{filter:{'isGroupFlag@$not':1}}).then(function(staffList){
      staffList.forEach(
        function(staff){
          staffArr.pushObject(Ember.Object.create({
            id:staff.get('id'),
            name:staff.get('name'),
            hasChoosed:false
          }));
        }
      );
    });
    this.store.query('user',{filter:{nurseGroup:{id:controller.get('id')}}}).then(function(staffList){
      staffList.forEach(
        function(staff){
          staffArr.pushObject(Ember.Object.create({
            id:staff.get('id'),
            name:staff.get('name'),
            hasChoosed:true
          }));
        }
      );
    });
    controller.set('staffList',staffArr);
    // var roomArr=[];
    // this.store.query('room',{filter:{'isGroupFlag@$not':1}}).then(function(roomList){
    //   roomList.forEach(
    //     function(room){
    //       roomArr.pushObject(Ember.Object.create({
    //         id:room.get('id'),
    //         name:room.get('name'),
    //         hasChoosed:false
    //       }));
    //     }
    //   );
    // });
    // this.store.query('room',{filter:{nurseGroup:{id:id}}}).then(function(roomList){
    //   roomList.forEach(
    //     function(room){
    //       roomArr.pushObject(Ember.Object.create({
    //         id:room.get('id'),
    //         name:room.get('name'),
    //         hasChoosed:true
    //       }));
    //     }
    //   );
    // });
    // controller.set('roomList',roomArr);

  }
});
